﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Pseudogenerator.Common.Generators.Core;

namespace Pseudogenerator.Common.Generators
{
    public class CuadraticCongruential
        : MixedCongruential
    {
        public uint d { get; set; }

        public override bool CanGenerateNext
        {
            get
            {
                if (a <= 0 ||
                    c <= 0 ||
                    d <= 0)
                    return false;
                if (m <= x0 ||
                    m <= a ||
                    m <= c ||
                    m <= d)
                    return false;

                return true;
            }
        }

        public override uint GetNextValue()
        {
            return ((d * (uint)Math.Pow(ActualValue, 2)) + (a * ActualValue) + c) % m;
        }

        public override string ToString()
        {
            return string.Format("X₁ = (({0} ٠ {1}²) + ({2} ٠ {1}) + {3}) mod {4}", d, x0, a, c, m);
        }
    }
}
